package top.dbpanda.cmsjpa.learn.thread.juc;

import java.util.Iterator;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * CopyOnWriteArrayList
 * 先复制一份然后向新容器添加元素
 * 增加完元素后，将引用指向新容器，原容器被GC手机
 */
public class TestCopyOnWriteArrayList {
    public static void main(String[] args) {
        //vector 向量类
        CopyOnWriteArrayList<String> names = new CopyOnWriteArrayList<>();
        names.add("zs");
        names.add("ls");
        names.add("ww");
        Iterator<String> iterator = names.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
            names.add("x");
        }
    }

}
